$(function () {
  let id = window.location.search.split("=")[1];
  console.log(id);
  $.ajax({
    url: BigNew.desk_article,
    data: {
      id,
    },
    success(backData) {
      console.log(backData);
      let data = backData.data;
      $(".article_title").text(data.title);
      $(".article_info").html(
        data.author +
          "&nbsp;发布于&nbsp;" +
          data.date +
          "&nbsp;&nbsp;分类:" +
          data.category +
          "&nbsp;&nbsp;阅读(" +
          data.read +
          ")&nbsp;&nbsp;" +
          "评论(" +
          data.comments +
          ")"
      );
      $("article_con").text(data.conent);
      $(".article_links a")
        .eq(0)
        .text(data.prev.title)
        .attr("href", "article.html?id=" + data.prev.id);
      $(".article_links a")
        .eq(1)
        .text(data.next.title)
        .attr("href", "article.html?id=" + data.next.id);
    },
  });

  $.ajax({
    url: BigNew.desk_get_comment,
    data: {
      articleId: id,
    },
    success(data) {
      console.log(data);
      $(".comment_count").text(data.data.length + "条评论");
      let html = template("comment_list", data);
      $(".comment_list_con").html(html);
    },
  });

  $(".form_group .comment_sub").click(function (e) {
    e.preventDefault();
    console.log("nihao ");
    let author = $(".comment_name").val().trim();
    let content = $(".comment_input").val().trim();
    if (author == "" || content == "") {
      return alert("内容不能为空");
    }
    $.ajax({
      url: BigNew.desk_post_comment,
      type: "post",
      data: {
        author,
        content,
        articleId: id,
      },
      success(backData) {
        if (backData.code == 201) {
          alert("评论待审核后发布");
          $(".comment_name").val("");
          $(".comment_input").val("");
        }
      },
    });
  });
  $.ajax({
    url: BigNew.desk_rank,
    success(backData) {
      let html = template("week_hot", backData);
      $(".hotrank_list").html(html);
    },
  });
    $.ajax({
        url: BigNew.desk_latest_comment,
        success(backData) {
            console.log(backData)
            let html = template('new-comments', backData);
            $('.comment_list').html(html);
        }
    });
     
  $.ajax({
    url: BigNew.desk_attention,
    success(backData) {
    
      let html = template('attention', backData);
      $('.guanzhu_list').html(html);
    }
  });
});
